package com.ylb.rent.config;

import com.ijpay.alipay.AliPayApiConfig;
import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.swing.plaf.PanelUI;
import java.util.HashMap;
import java.util.Map;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/6/30 10:13
 */

@Configuration
public class RabbitMQConfig {

    public static final String ORDER_EXCHANGE_NAME="orderExchange";
    public static final String ORDER_QUEUE_NAME="orderInsertQueue";
    public static final String ORDER_ROUTE_KEY="insert";
    public static final String ORDER_DEATH_EXCHANGE_NAME="orderDeathExchange";
    public static final String ORDER_DEATH_QUEUE_NAME="orderCancelDeathQueue";
    public static final String ORDER_DEATH_ROUTE_KEY="cancel";

    @Bean
    public DirectExchange orderDeathExchange(){
        return ExchangeBuilder.directExchange(ORDER_DEATH_EXCHANGE_NAME).build();
    }

    @Bean
    public Queue orderDeathQueue(){
        return new Queue(ORDER_DEATH_QUEUE_NAME);
    }

    @Bean
    public Binding deathBinding(){
        return BindingBuilder.bind(orderDeathQueue()).to(orderDeathExchange()).with(ORDER_DEATH_ROUTE_KEY);
    }

    @Bean
    public DirectExchange orderExchange(){
        return ExchangeBuilder.directExchange(ORDER_EXCHANGE_NAME).build();
    }

    @Bean
    public Queue orderQueue(){
        Map<String,Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange",ORDER_DEATH_EXCHANGE_NAME);
        args.put("x-dead-letter-routing-key",ORDER_DEATH_ROUTE_KEY);
        return new Queue(ORDER_QUEUE_NAME,true,false,false,args);
    }

    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(ORDER_ROUTE_KEY);
    }

}
